package com.gaoqi.springboot_shiro.utils;

import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * 生成随机盐
 */

public class SaltUtils {

    public static String getSalt(int n) {
        String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase() + "1234567890" + "/*-+)(*&&^%$#@!";
        char[] chars = s.toCharArray();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char aChar = chars[new Random().nextInt(chars.length)];
            stringBuilder.append(aChar);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        String salt = SaltUtils.getSalt(8);
        System.out.println(salt);
    }
}
